package com.ruoyi.web.controller.com;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.system.service.ISysConfigService;
import com.ruoyi.system.service.ISysUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Conference;
import com.ruoyi.system.service.IConferenceService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会议Controller
 *
 * @author ruoyi
 * @date 2024-06-07
 */
@Controller
@RequestMapping("/system/conference")
public class ConferenceController extends BaseController {
    private String prefix = "system/conference";

    @Autowired
    private IConferenceService conferenceService;
    @Autowired
    private ISysUserService userService;

    @RequiresPermissions("system:conference:view")
    @GetMapping()
    public String conference() {
        return prefix + "/conference";
    }

    /**
     * 查询会议列表
     */
    @RequiresPermissions("system:conference:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Conference conference) {
        startPage();
        List<Conference> list = conferenceService.selectConferenceList(conference);
        // list.forEach(item->{
        //    SysUser sysUser =userService.selectUserById(Long.valueOf(item.getConUserId()));
        //    item.setSysUser(sysUser);
         // });
        return getDataTable(list);
    }

    /**
     * 导出会议列表
     */
    @RequiresPermissions("system:conference:export")
    @Log(title = "会议", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Conference conference) {
        List<Conference> list = conferenceService.selectConferenceList(conference);
        ExcelUtil<Conference> util = new ExcelUtil<Conference>(Conference.class);
        return util.exportExcel(list, "会议数据");
    }

    /**
     * 新增会议
     */
    @GetMapping("/add")
    public String add(ModelMap modelMap) {
        List<SysUser> sysUsers = userService.selectUserList(new SysUser());
        modelMap.put("sysUsers", sysUsers);
        return prefix + "/add";
    }

    /**
     * 新增保存会议
     */
    @RequiresPermissions("system:conference:add")
    @Log(title = "会议", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Conference conference) {
        conference.setCreatedBy(ShiroUtils.getSysUser().getUserName());
        conference.setCreatedTime(new Date());
        return toAjax(conferenceService.insertConference(conference));
    }

    /**
     * 修改会议
     */
    @RequiresPermissions("system:conference:edit")
    @GetMapping("/edit/{conId}")
    public String edit(@PathVariable("conId") Long conId, ModelMap mmap) {
        Conference conference = conferenceService.selectConferenceByConId(conId);
        mmap.put("conference", conference);
        return prefix + "/edit";
    }

    /**
     * 修改保存会议
     */
    @RequiresPermissions("system:conference:edit")
    @Log(title = "会议", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Conference conference) {
        conference.setCreatedBy(ShiroUtils.getSysUser().getUserName());
        conference.setCreatedTime(new Date());
        return toAjax(conferenceService.updateConference(conference));
    }

    /**
     * 删除会议
     */
    @RequiresPermissions("system:conference:remove")
    @Log(title = "会议", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(conferenceService.deleteConferenceByConIds(ids));
    }
}
